package com.ruoyi.common.utils.wxpay;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class MyConfig extends WXPayConfig{

    private byte[] certData;

    public MyConfig() throws Exception {
        String certPath = "C:/Users/Administrator/Documents/WeChat Files/wxid_wd9kpgtr9djr22/FileStorage/File/2022-04/1625068418_20220427_cert/apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }
    //AppID
    public String getAppID() {
        return "wxe66b24b0cc716cc7";
    }
    //商户id / 商户号
    public String getMchID() {
        return "1625068418";
    }
    //商户密钥
    public String getKey() {
        return "sdsiojsl1421xc574s5d1s515sd412x1";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    IWXPayDomain getWXPayDomain() {
        // 这个方法需要这样实现, 否则无法正常初始化WXPay
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {

            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }

}
